package com.mapforge.selection;

import java.awt.Point;

public class ComparablePoint extends Point implements Comparable<Point>,
		Cloneable {

	/**
	 * Default serail ID, here to remove warnings.
	 */
	private static final long serialVersionUID = 1L;

	public ComparablePoint() {
		this(0, 0);
	}

	public ComparablePoint(Point p) {
		this(p.x, p.y);
	}

	public ComparablePoint(int x, int y) {
		super(x, y);
	}

	@Override
	public int compareTo(Point p) {
		if (p != null) {
			if (p.x == this.x && p.y == this.y) {
				return 0;
			} else if (p.y == this.y && p.x != this.x) {
				return this.x < p.x ? -1 : 1;
			} else {
				return this.y < p.y ? -1 : 1;
			}
		} else {
			return 1;
		}
	}

	public boolean equals(Object obj) {
		if (obj != null && obj instanceof Point) {
			Point p = (Point) obj;
			return this.x == p.x && this.y == p.y;
		} else {
			return false;
		}
	}

	public Object clone() {
		return new ComparablePoint(this.x, this.y);
	}

	public static void main(String[] args) {
		Point p = new Point();
		Point p2 = new Point(0, 0);
		System.out.println(p.hashCode() + " " + p2.hashCode() + " "
				+ p2.equals(p));
	}
}